package com.note7_6;

import java.io.*;

public class Question2 {

	/*
	 * 附件 chaoxian.txt是个文本文件，用程序把其中的金正恩替换成 金三胖，
 	 * 提示：把内容取出来，替换后，写入文件。
	 */
	public static void main(String[] args) {
		FileInputStream fip = null;
		InputStreamReader ipd = null;
		BufferedReader bfr = null;
		BufferedWriter bfw = null;
		try {
			fip = new FileInputStream("C:/Users/60973/Desktop/北大青鸟/chaoxian.txt");
			ipd = new InputStreamReader(fip,"GBK");
			bfr = new BufferedReader(ipd);
			String str = null;
			StringBuilder newstr = new StringBuilder();
			while((str = bfr.readLine()) != null){
				str = str.replace("金正恩", "金三胖");
				newstr.append(str);
				newstr.append("\r\n");
			}
			bfw = new BufferedWriter(new FileWriter("C:/Users/60973/Desktop/北大青鸟/chaoxian1.txt"));
			bfw.write(newstr.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(bfr != null){
				try {
					bfr.close();
				} catch (IOException e) {
					System.out.println("输入流关闭失败");
					e.printStackTrace();
				}
			}
			if(bfw != null){
				try {
					bfw.close();
				} catch (IOException e) {
					System.out.println("输出流关闭失败");
					e.printStackTrace();
				}
			}
		}
	}
}
